﻿@{
    ViewBag.Title = "添加奖品";
}


<link href="~/Content/js/layer.mobile/layer.m/need/layer.css" rel="stylesheet" />

<div class="pageheader">
    <h2><i class="fa fa-user"></i>添加奖品</h2>
</div>
@using (Html.BeginForm("Create", "Goods", FormMethod.Post, new { name = "myform", id = "myform", @class = "form-horizontal form-bordered" }))
{
    <div class="form-group">
        <label class="col-sm-3 control-label">名称</label>
        <div class="col-sm-6">
            <input type="text" name="Name" class="form-control" required value="">
        </div>
        </div>
    <div class="form-group">
            <label class="col-sm-3 control-label">需要积分</label>
            <div class="col-sm-6">
                <input type="text" name="RequireJF" class="form-control" required value="">
            </div>
     </div>
      <div class="form-group">
                <label class="col-sm-3 control-label">库存</label>
                <div class="col-sm-6">
                    <input type="text" name="Stock" class="form-control" required value="">
                </div>
      </div>

    <div class="form-group" style="text-align:center;">
        <div class="col-sm-12">
            <p class="items"><button type="button" id="yz-img" class="submit-btn" style="height:33px;">上传奖品照片</button></p>
            <span></span>
            @*<p class="items"><button type="button" id="ex-img" class="submit-btn" style="height:33px;background-color:#B5B5B6;">点击查看示例照片</button></p>
            <input type="hidden" name="DoctorCertificate" id="DoctorCertificate" />*@
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label">图片</label>
        <div class="col-sm-6">
            <input type="text" name="GoodImg" class="form-control" style="display:none;" value="">
            <img id="GoodImg" style="max-width:300px;" src="" />
        </div>
    </div>

    <div class="submit-footer">
        <button class="btn btn-primary" id="btnSave">提交</button>
    </div>
}
@section scripts
{
 
<script src="~/Content/js/layer.mobile/layer.m/layer.m.js"></script>
<script src="~/Content/js/plupload/js/plupload.full.min.js"></script>
 
 <script>
     $(function () {

         ///奖品图片上传
         var uploader = new plupload.Uploader({
             browse_button: 'yz-img', //触发文件选择对话框的按钮，为那个元素id
             url: '/api/UploadApprove/',
             multi_selection: false,
             max_file_size: '1mb',
             filters: [
             { title: "Image files", extensions: "jpg,png,jpeg" }
             ],
         });

         //绑定各种事件，并在事件监听函数中做你想做的事
         uploader.bind('FilesAdded', function (uploader, files) {
             uploader.start(); //调用实例对象的start()方法开始上传文件，当然你也可以在其他地方调用该方法
         });
         uploader.bind('UploadProgress', function (uploader, file) {
             //console.log(uploader);
             $("#yz-img").html("文件上传中，请稍等..." + file.percent + "%");
             if (file.percent == 100) {
                 $("#yz-img").html("上传完成！点击可重新上传");

             }

         });

         uploader.bind('UploadComplete', function (uploader, files) {
             //console.log(files);
         });

         uploader.bind('FileUploaded', function (up, file, result) {
             //console.log(result.response);
             console.log("------");
             console.log(result);
             var obj = $.parseJSON(result.response);
             $("#GoodImg").attr("src", obj.uploadResult);
             $("input[name='GoodImg']").val(obj.uploadResult);
             $("#DoctorCertificate").val(result.response);
             ///上传成功后注册查看事件
             $("#ex-img").on("click", function () {
                 layer.open({
                     title: '奖品图片',
                     content: "<img width='100%' src=" + obj.uploadResult + ">"
                 })
             });
         });

         uploader.init();

     });



</script>

}